package com.icinfo.cloud.provider.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：附件对应请求内容类型枚举
 *
 * @author xiangyuyu
 * @date 2022/3/2 10:02
 */
@AllArgsConstructor
public enum AttachmentRequestContentTypeEnum {
    /**
     * 附件类型枚举
     */
    pdf("pdf", "application/pdf"),
    ppt("ppt", "application/vnd.ms-powerpoint"),
    pptx("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
    doc("doc", "application/msword"),
    docx("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
    xls("xls", "application/vnd.ms-excel"),
    xlsx("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    rar("rar", "application/octet-stream"),
    csv("csv", "application/octet-stream"),
    zip("zip", "application/zip"),
    jpg("jpg", "image/jpeg"),
    jpeg("jpeg", "image/jpeg"),
    png("png", "image/png"),
    bmp("bmp", "image/bmp"),
    gif("gif", "image/gif"),
    html("bmp", "text/html"),
    vsd("vsd", "application/vnd.visio");


    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;

    /**
     * 根据code获取value
     *
     * @param code 编码
     * @return 描述内容
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (AttachmentRequestContentTypeEnum e : AttachmentRequestContentTypeEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return null;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     * @author XiangYuYu
     * @date 2021/09/15
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (AttachmentRequestContentTypeEnum e : AttachmentRequestContentTypeEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
